package me.huanmeng.heater;

import me.huanmeng.heater.command.Command;
import me.huanmeng.heater.event.Event;
import me.huanmeng.heater.heather.Server;
import me.huanmeng.heater.heather.ServerImpl;
import me.huanmeng.heater.object.ChannelInfo;
import me.huanmeng.heater.object.Guild;
import me.huanmeng.heater.object.UserInfo;
import me.huanmeng.heater.plugin.Plugin;
import me.huanmeng.heater.sender.Channel;
import me.huanmeng.heater.sender.CommandSender;
import me.huanmeng.heater.sender.User;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.logging.Level;

/**
 * 2021/9/26<br>
 * Heater<br>
 *
 * @author huanmeng_qwq
 */
public class Heater {
    private static ServerImpl server;

    public static void setServer(ServerImpl imp) {
        if (Heater.server != null) {
            return;
        }
        Heater.server = imp;
    }

    /**
     * 输出信息
     *
     * @param level    级别
     * @param messages 信息
     */
    private static void log(Level level, Object... messages) {
        server.log(level, messages);
    }

    public static Server getServer() {
        return server;
    }

    /**
     * 名字
     *
     * @return 名字
     */
    public static String getName() {
        return server.getName();
    }

    /**
     * 获取这个服务器的版本
     *
     * @return 版本
     */
    public static String getVersion() {
        return server.getVersion();
    }


    public static int getIndentFactor() {
        return 2;
    }

    public static <T extends Event> T callEvent(T event) {
        return server.callEvent(event);
    }

    public static void registerEvents(Plugin plugin, Object listener) {
        server.registerEvents(plugin, listener);
    }

    @Nullable
    public static Channel getChannel(@NotNull String id) {
        return server.getChannel(id);
    }

    public static void setChannel(@NotNull ChannelInfo channel) {
        server.setChannel(channel);
    }

    @Nullable
    public static User getUser(@NotNull String id) {
        return server.getUser(id);
    }
    public static UserInfo getUserInfo(@NotNull String id) {
        return server.getUserInfo(id);
    }
    public static void registerCommand(@NotNull Plugin plugin, @NotNull Command command){
        server.registerCommand(plugin, command);
    }

    public static void setUser(@NotNull UserInfo userInfo) {
        server.setUser(userInfo);
    }

    public static void executeCommand(@NotNull CommandSender sender, @Nullable Channel channel, @NotNull String line) {
        server.executeCommand(sender, channel, line);
    }

    public static Guild getGuild(String id){
        return server.getGuild(id);
    }

    public static Collection<Guild> getGuilds(){
        return server.getGuilds();
    }
    public static void setGuild(Guild guild) {
        server.setGuild(guild);
    }
}
